<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<a href="#/a">跳转到/a</a>
<a href="#/b">跳转到/b</a>
<div id="root" style="border:1px solid red;"></div>
<script>
    //当浏览器的hash值发生改变之后
    window.addEventListener('hashchange', () => {
        console.log('window.location.hash', window.location.hash);

        const hash = window.location.hash.slice(1);
        root.innerHTML = hash;
    });
</script>
</body>
</html>